import { mapState } from "vuex";
import { debounce } from "xe-utils";
import OrderService from "@/api/order/OrderService.js";

const ExportDefault = {
    data() {
        return {
        };
    },
    props: {
        row: {
            type: Object,
            default: () => {
                return {};
            },
        },
    },

    mounted() {
        
        
      },
    computed: {
        ...mapState("user", ["user"]),
        ...mapState("orders", ["orderPosInfo", "CARRY_ROW",]),
 
    },
    methods: {
        async initCommon(){


            //查询原单信息
            let  resList={}
            var modType=JSON.parse(sessionStorage.getItem("ppmCondition")).modType;
            if (modType=='50200002'){
                resList=  await this.qryOldOrdInfo();
            }else{
                resList=  await this.qryOldInstInfo();
                this.BTypeHide(resList);
            }
            let lastStateCd = JSON.parse(  sessionStorage.getItem("changeRow")).lastStateCd;debugger
            if ((lastStateCd == "50030002"||JSON.parse(  localStorage.getItem("changeConfig")).selectBill== "50030002")&&JSON.parse(sessionStorage.getItem("ppmCondition")).serviceOfferId!='5010100001') {
                for (let i in this.formData) {
                  if ( this.formData[i].colId == "orderDate" || this.formData[i].colId == "ORDER_DATE" ) {
                    //需求单起隐藏订单要求完成日期
                    this.formData[i].colId ="reqOrderDate";
                    this.formData[i].fieldId ="reqOrderDate";
                    this.formData[i].attrId='100012033';
                    this.formData[i].id=i.split('-')[0]+'-100012033';
                    // this.formData[i].isshow = false;
                    // this.SetRequired("0", i);
                  }
                  console.info("需求单"+i);
                }
            } else {
                for (let i in this.formData) {
                  if ( this.formData[i].colId == "reqOrderDate" || this.formData[i].colId == "REQ_ORDER_DATE"  ) {
                    //订单起隐藏需求单要求完成日期
                    //需求单起隐藏订单要求完成日期
                    this.formData[i].colId ="orderDate";
                    this.formData[i].fieldId ="orderDate";
                    this.formData[i].id=i.split('-')[0]+'-100010082';
                  }
                  console.info("订单"+i);
                }
            }
            return resList;

        },
        Isshow(value, id) {//属性显示隐藏
            if (value == '1') {
                if (document.getElementById(id)) {
                    document.getElementById(id).style.display = 'block'
                }
            }
            if (value == '0') {
                if (document.getElementById(id)) {
                    document.getElementById(id).style.display = 'none'
                }
            }
        },

        // SetRequired(value, id) {//必填验证设置
        //     if (document.getElementById(id)) {
        //         let classVal = document.getElementById(id).getAttribute("class");
        //         if (value == '1') {//增加必填验证
        //             classVal = classVal.concat(" is-required")
        //             document.getElementById(id).setAttribute('class', classVal)
        //         }
        //         if (value == '0') {//去掉必填验证
        //             classVal = classVal.replace("is-required", "");
        //             document.getElementById(id).setAttribute('class', classVal)
        //         }
        //     }
        // },

        //获取input-grid选中的值
        getRowValue(val) {
            
        },

        //获取input-grid选中的值
        getInputGridValue() {
        },

        //加载dialogInput组件上的congfig配置
        dialogInputConfig() {
            return {}
        },

        //获取插件返回的值
        getPluginValue(obj, key) {
            
            
            if (key == '100013695') {//发展人信息
                if (obj.index == '0') {//第一发展人
                    this.formData['1688-141000467'].value = obj.row.CHANNEL_NBR;//渠道编码
                    this.formData['1688-141000468'].value = obj.row.STAFF_ID;//发展人标识
                }
                if (obj.index == '1') {//第二发展人
                    this.formData['1689-141000467'].value = obj.row.CHANNEL_NBR;//渠道编码
                    this.formData['1689-141000468'].value = obj.row.STAFF_ID;//发展人标识
                }
            }
        },

        //展开收起
        ctrlfold(fold, id) {
            
            
            // if (id == "10460285") {//MSTP甲乙端业务信息外框展示 
            //     if (fold) {  //业务信息展开收起
            //         this.Isshow("1", "10461239");
            //     } else {
            //         this.Isshow("0", "10461239");
            //     }
            // }
            // if (id == "10460167") {//资费信息展开收起

            // }
        },

        //B1业务展示*是否修改合同期限、合同终止日期 其他业务隐藏  受理运营商非中国电信非中国网通
         BTypeHide(resList) {debugger;
            console.log(resList);
            for (let i in this.formData) {
                if (resList.ordProdInsts&&resList.ordProdInsts.length>0&&resList.ordProdInsts[0].orderSourceId != 10000 && resList.ordProdInsts[0].orderSourceId != 10010) {
                    if (this.formData[i].colId == '142000765') {//是否修改合同期限
                        this.formData[i].isshow = true;
                       // this.SetRequired("1", i);
                        this.SetRequired({ attrName:'是否修改合同期限', formkey: i, reqName:'empty', reqStatus:true});
                    }
                    // if (this.formData[i].colId == '142002037') {//合同终止日期
                    //     this.formData[i].isshow = true;
                    //    // this.SetRequired("1", i);
                    //     this.SetRequired({ attrName:'合同终止日期', formkey: i, reqName:'empty', reqStatus:true});
                    // }
                } else {
                    if (this.formData[i].colId == '142000765') {//是否修改合同期限
                        this.formData[i].isshow = false;
                        //this.SetRequired("0", i);
                        this.SetRequired({ attrName:'', formkey: i, reqName:'empty', reqStatus:false});
                    }
                    if (this.formData[i].colId == '142002037') {//合同终止日期
                        this.formData[i].isshow = false;
                        //this.SetRequired("0", i);
                        this.SetRequired({ attrName:'', formkey: i, reqName:'empty', reqStatus:false});
                    }
                }

            }
        },
        //非正常变更查询原单过程数据
        async qryOldOrdInfo(){
            let conditions = {
                modType: JSON.parse(sessionStorage.getItem("ppmCondition")).modType,
                custId: this.CARRY_ROW.custId,
                custSoNumber: JSON.parse(sessionStorage.getItem("changeRow")).custSoNumber,
                orderItemIds: JSON.parse(sessionStorage.getItem("changeRow")).orderItemId,
                scopeInfos: [
                    { "scope": "acctItems" },
                    { "scope": "acctItemOrgs" },
                    { "scope": "customerOrders" },
                    { "scope": "orderItems" },
                    { "scope": "orderItemAttrs" },
                    { "scope": "orderItemFiles" },
                    { "scope": "ordProdInstsAttrs" },
                    { "scope": "ordProdInsts" },
                    { "scope": "ordOfferInsts" },
                    { "scope": "ordOfferInstFeeInfos" },
                    { "scope": "ordProdInstAcctRels" },
                    { "scope": "ordOfferInstFeeAttrs" },
                    { "scope": "orderContactInfos" }
                   ]
            };
            let resList = await OrderService.getOldOrdAttrForModifyPage(conditions);debugger;
            
            return  resList.meta.orderDetails[0];
        },
        //正常变更查询原单实例数据
        async qryOldInstInfo(){
            let conditions = {
                modType: JSON.parse(sessionStorage.getItem("ppmCondition")).modType,
                custId: JSON.parse(sessionStorage.getItem("changeRow")).custId,
                custSoNumber: JSON.parse(sessionStorage.getItem("changeRow")).custSoNumber,
                orderItemIds: JSON.parse(sessionStorage.getItem("changeRow")).orderItemId,
                offerInstId: JSON.parse(sessionStorage.getItem("changeRow")).offerInstId,
                scopeInfos: [
                    { "scope": "acctItems" },
                    { "scope": "acctItemOrgs" },
                    { "scope": "customerOrders" },
                    { "scope": "prodInsts" },
                    { "scope": "prodInstAttrs" },
                    { "scope": "offerInsts" },
                    { "scope": "offerInstAttrs " },
                    { "scope": "offerInstFeeInfos" },
                    { "scope": "prodInstAcctRels" },
                    { "scope": "offerInstFeeAttrs" },
                    { "scope": "prodInstContact" },
                   ]
            };
            let resList = await OrderService.getOldAttrForModifyPage(conditions);debugger;
            
            let orderDetails=resList.meta;
            orderDetails.ordProdInsts=orderDetails.prodInsts;
            orderDetails.ordProdInstsAttrs=orderDetails.prodInstAttrs
            orderDetails.ordOfferInsts=orderDetails.offerInsts;
            orderDetails.ordOfferInstFeeInfos=orderDetails.offerInstFeeInfos;
            orderDetails.ordProdInstAcctRels=orderDetails.prodInstAcctRels;
            orderDetails.ordOfferInstFeeAttrs=orderDetails.offerInstFeeAttrs;
            orderDetails.orderContactInfos=orderDetails.prodInstContact;
            
            return  orderDetails;
        },
    },

}

export default ExportDefault;
